// pages/problem/problem.js
let feedbackApi = require('../common/showToast.js');
const getToken = require('../../utils/get_token.js');
let cookie, token;
const ckToken = async (that) => {//token确认
  let nTime = Math.floor(new Date().getTime() / 1000);
  let oldTime = wx.getStorageSync('ntime') || 0;
  if (nTime < oldTime)//现在的时间小于到期时间
  {
    detail(that);
  } else {
    let tokens = await getToken.getToken();
    detail(that);
  }
}

const detail = (that) => {
  let params = ['common/feedBack/list', {"type":3}]
  getToken.getData(function (res) {
    console.log(res.data);
    let lists = res.data.data;
    that.data.list = lists[0].answers
    that.setData({
      list: that.data.list
    })
  }, ...params)
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    boolT: true
  },
  showAn: function (e) {//显示
    var that = this;
    var newArr = [];
    var kid = e.currentTarget.dataset.id;
    that.data.list.forEach((item, index, arr) => {
      if (item.id == kid) {
        item.show = !item.show;
      } else {
        item.show = false;
      }
      newArr.push(item);
    })
    that.setData({
      list: newArr
    })
  },
  hideAn: function (e) {//隐藏
    var that = this;
    var newArr = [];
    that.data.list.forEach((item, index, arr) => {
      item.show = false;
      newArr.push(item);
    })
    that.setData({
      list: newArr
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    cookie = wx.getStorageSync('cookie') || '';
    token = wx.getStorageSync('token') || '';
    ckToken(that);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})